package OptimalAlgorithm.TwoPointTechnique;
//购物车内的商品价格按照升序记录于数组 price。请在购物车中找到两个商品的价格总和刚好是 target。若存在多种情况，返回任一结果即可。
//输入：price = [3, 9, 12, 15], target = 18
//输出：[3,15] 或者 [15,3]
public class TwoSum {
    public int[] twoSum(int[] price, int target) {
        int right = price.length - 1;
        int left = 0;
        while (left < right){
            if(price[left] + price[right] < target){
                left++;
            }else if(price[left] + price[right] > target){
                right--;
            }else {
                return new int[]{price[left],price[right]};
            }
        }
        return null;
    }
}
